//
//  UINavigationBar+Theme.swift
//  MasterBoy
//
//  Created by kyson on 2024/9/21.
//

import Foundation
import UIKit

extension UINavigationBar {

    @available(*, deprecated, message: "请使用 setDynamicNavigationBarBackgroundColor2 代替")
    private func setDynamicNavigationBarBackgroundColor() {
        tintColor = ThemeManager.shared.dynamicBackgroundColor()
        barTintColor = ThemeManager.shared.dynamicBackgroundColor()
    }
    
    
    func setDynamicNavigationBarBackgroundColor2() {
        
        /*
        let appear = UINavigationBarAppearance()
        appear.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor(colorHex: 0x333333)]
        appear.backgroundColor = UIColor.white
        bar.standardAppearance = appear
        bar.scrollEdgeAppearance = appear
        // 带scroll滑动的页面
        self.navigationBar.scrollEdgeAppearance?.shadowColor = .clear
        // 常规页面
        self.navigationBar.standardAppearance.shadowColor = .clear
        */
        
        
        // 设置导航栏背景色
        if #available(iOS 13.0, *) {
            titleTextAttributes = [
                NSAttributedString.Key.foregroundColor: ThemeManager.shared.dynamicTextColor()
            ]
            
            let appearance = UINavigationBarAppearance()
            appearance.configureWithOpaqueBackground()//将导航栏设置为不透明背景，不会显示导航栏背后的内容。
            //appearance.configureWithTransparentBackground()//将导航栏设置为透明背景，允许显示背后的内容（如滚动内容）。
            
            appearance.backgroundColor = ThemeManager.shared.dynamicForgroundColor()
            
            appearance.backgroundImage = UIImage() // 设置透明背景图片
            appearance.shadowImage = UIImage() // 去掉阴影
            
            appearance.shadowColor = .clear
            standardAppearance = appearance
            scrollEdgeAppearance = appearance
 
        } else {
            shadowImage = UIImage()
            
            barTintColor = UIColor.white
            tintColor = UIColor.init(colorHex: 0x333333)
        }
        
    }
    
}

